package com.cuile.littletools

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.navigation.findNavController
import com.google.zxing.client.android.Intents

class MainActivity : BaseActivity() {
    override fun initCreateActivity(savedInstanceState: Bundle?) {
        setContentView(R.layout.activity_main)

        requestPermission(Manifest.permission.ACCESS_FINE_LOCATION, 1) {}
        requestPermission(Manifest.permission.ACCESS_COARSE_LOCATION, 2) {}
        requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 3) {}
        requestPermission(Manifest.permission.READ_PHONE_STATE, 4) {}
    }

    override fun onSupportNavigateUp() = findNavController(R.id.mainNavHostFragment).navigateUp()

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        Log.i("requestCode", requestCode.toString())
        when (requestCode) {
            1 -> {
                if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                }
            }
            else -> {
                Toast.makeText(this, "Permission is failed", Toast.LENGTH_SHORT).show()
            }
        }
    }
}
